<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <link rel="Bookmark" href="favicon.ico" >
    <link rel="Shortcut Icon" href="favicon.ico" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/assets/H-ui/static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/assets/css/bootstrap.css" />
        <script src="${pageContext.request.contextPath}/assets/js/jquery.min.js"></script>
        <script src="${pageContext.request.contextPath}/assets/js/bootstrap.min.js"></script>
    <title>小结评语列表 - 小结评语管理 </title>
</head>
<body>

<div class="container">
    <div class="col-lg-10 col-lg-offset-1">
        <div class="panel-body">
            <div class="text-c">
                <form action="${pageContext.request.contextPath}/remark/remarkList.action" id="first">
                    <input type="text" value="1" name="num" id="num" hidden>
                   科室 <select id="deskName" name="deskName">
                       <c:if test="${not empty desks}">
                           <option></option>
                           <c:forEach items="${desks}" var="desk">
                               <option value="${desk.deskName}" ${param.deskName eq desk.deskName?'selected':''}>${desk.deskName}</option>
                           </c:forEach>
                       </c:if>
                    </select>
                  <%--科室：<input type="text" name="deskName" id="deskName" value="${param.deskName}">--%>
                    工作人员：<input type="text" name="workName" id="workName" value="${param.workName}">
                    <button type="submit" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
                </form>
            </div>
        </div>
                <table class="table table-hover table-bordered<%--table table-border table-bordered table-hover table-bg table-sort--%>">
                    <thead>
                    <tr class="text-c">
                        <th hidden></th>
                        <th width="40" style="text-align: center">科室</th>
                        <th width="90" style="text-align: center">工作人员</th>
                        <th width="70" style="text-align: center">评语名称</th>
                        <th width="100" style="text-align: center">评语小结内容</th>
                        <th width="100" style="text-align: center">操作</th>
                    </tr>
                    </thead>
                    <tbody style="text-align: center">
                    <c:if test="${not empty page}">
                        <c:forEach items="${page.list}" var="remark">
                    <tr class="text-c">
                        <td hidden>${remark.remarkId}</td>
                        <td>${remark.work.desk.deskName}</td>
                        <td>${remark.work.workName}</td>
                        <td>${remark.remarkName}</td>
                        <td>${remark.getRemarkField()}</td>
                        <%--<td class="td-status"><span class="label label-success radius">已启用</span></td>--%>
                        <td class="td-manage">
                            <a title="编辑" onclick="updateRemark(this)" class="btn-primary btn-sm" style="text-decoration:none">详情</a>
                            <%--<a title="编辑" class="btn-primary btn-sm" data-toggle='modal' data-target='#addModal1' style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>--%>
                            <a title="删除" onclick="delectRemark(${remark.remarkId})" class="btn-danger btn-sm" style="text-decoration:none">删除</a>
                        </td>
                    </tr>
                        </c:forEach>
                    </c:if>
                    </tbody>
                </table>
        <a class="btn-primary btn-sm" data-toggle='modal' data-target='#addModal' style="z-index: 1">添加评语</a>
        <div id="page" style="float: right" align="center">
                         当前第${page.pageNum}页, 总共${page.pages}页，每页${page.pageSize}行，总共${page.total}行。
                         <a id="firstPage" class="btn-sm btn-primary" onclick="changeNum(${page.prePage})">上一页</a>
                         <a id="lastPage" class="btn-sm btn-primary" onclick="changeNum(${page.nextPage})">下一页</a>
                     </div>

       <%--增加的模态框--%>
        <%--评语类表添加模态框部分--%>
        <div class="modal fade" id="addModal" style="z-index:99999" >
            <div class="modal-dialog" style="width: 600px;z-index: 99999">
                <div class="modal-content">
                    <!-- 模态框头部 -->
                    <div class="modal-header" style="text-align: center;z-index: 1">
                        <label>新增评语模板</label>
                        <%--<button type="button" class="close" data-dismiss="addModal">&times;</button>--%>
                    </div>
                    <div class="modal-body">
                        <form action="${pageContext.request.contextPath}/remark/addRemarks.action" method="post" id="addForm">
                            评语内容：<br>
                            <textarea name="remarkField" style="width: 500px;height: 200px" id="remarkField"></textarea>
                            <span  id="remarkField_input" style="font-size: 20px;color: red"></span>
                            <br>
                            <br>
                            <br>
                            评语简称：<br>
                            <input type="text" name="remarkName" id="remarkName"><br>
                            <span  id="remarkName_input" style="font-size: 20px;color: red"></span>
                            <br>
                            <br>
                            <input type="button" value="提交" onclick="addRemark()">
                            <input type="button" value="返回" onclick="returnRemarkList()">
                        </form>
                    </div>
                    <div class="modal-footer">
                    </div>
                </div>
            </div>
        </div>
        <div class="modal fade" id="updateModal" style="z-index:99999" >
            <div class="modal-dialog" style="width: 600px;z-index: 99999">
                <div class="modal-content">
                    <!-- 模态框头部 -->
                    <div class="modal-header" style="text-align: center;z-index: 1">
                        <label>修改评语模板</label>
                        <%--<button type="button" class="close" data-dismiss="addModal">&times;</button>--%>
                    </div>
                    <div class="modal-body">
                        <form action="${pageContext.request.contextPath}/remark/updateRemark1.action" method="post" id="updateForm">
                            <input type="text" hidden  name="remarkId1" id="remarkId1">
                            评语内容：<br>
                            <textarea name="remarkField1" style="width: 500px;height: 200px" id="remarkField1"></textarea>
                            <span  id="remarkField_input1" style="font-size: 20px;color: red"></span>
                            <br>
                            <br>
                            <br>
                            评语简称：<br>
                            <input type="text" name="remarkName1" id="remarkName1"><br>
                            <span  id="remarkName_input1" style="font-size: 20px;color: red"></span>
                            <br>
                            <br>
                            <input type="button" value="提交" onclick="updateRemark1()">
                            <input type="button" value="返回" onclick="returnRemarkList()">
                        </form>
                    </div>
                    <div class="modal-footer">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function () {
        if(${page.isLastPage}){
            $("#lastPage").removeAttr("onclick");
        }
    });
    function changeNum(obj) {
        var form=$("#first");
        $("input[name='num']").val(obj);
        form.method="post";
        form.submit();
    }

    function updateRemark1() {
        var flag=true;
        var remarkField1=$("#remarkField1").val();
        var remarkName1=$("#remarkName1").val();
        var remarkField_input1=$("#remarkField_input1");
        var remarkName_input1=$("#remarkName_input1");
        var remarkId1=$("#remarkId1").val();
        var addForm1=$("#addForm1");
        remarkField_input1.text("");
        remarkName_input1.text("");
        if(remarkField1==null||remarkField1==''){
            remarkField_input1.text("修改内容不能为空");
            flag=false;
        }
        if(remarkName1==null||remarkName1==""){
            remarkName_input1.text("修改简称不能为空");
            flag=false;
        }
        if(flag){
            $.post("${pageContext.request.contextPath}/remark/updateRemark1.action",
                {"remarkField1":remarkField1,"remarkName1":remarkName1,"remarkId1":remarkId1},
                function (result) {
                    console.log(result);
                    console.log(typeof result);
                    if(result==true){
                        alert("修改成功");
                        window.location.href="${pageContext.request.contextPath}/remark/remarkList.action";
                    }else if(result==false){
                        alert("修改失败");
                    }
                })
        }

    }
    function returnRemarkList() {
        window.location.href="${pageContext.request.contextPath}/remark/remarkList.action";
    }
    function updateRemark(obj) {
        var tds= $(obj).parent().parent().find('td');
        $("#remarkId1").val(tds.eq(0).text());
        $("#remarkField1").val(tds.eq(1).text());
        $("#remarkName1").val(tds.eq(2).text());
        $('#updateModal').modal({show:true});
    }

function addRemark() {
    var flag=true;
    var workId=${sessionScope.work.workId};
    var remarkField=$("#remarkField").val();
    var remarkName=$("#remarkName").val();
    var remarkField_input=$("#remarkField_input");
    var remarkName_input=$("#remarkName_input");
    var addForm=$("#addForm");
    remarkField_input.text("");
    remarkName_input.text("");
    if(remarkField==null||remarkField==''){
        remarkField_input.text("评论内容不能为空");
        flag=false;
    }
    if(remarkName==null||remarkName==""){
        remarkName_input.text("评论简称不能为空")
        flag=false;
    }
    if(flag){
      $.post("${pageContext.request.contextPath}/remark/addRemarks.action",
          {"remarkField":remarkField,"remarkName":remarkName,"workId":workId},
      function (result) {
          console.log(result);
          console.log(typeof result);
          if(result==true){
              alert("添加成功");
              window.location.href="${pageContext.request.contextPath}/remark/remarkList.action";
          }else if(result==false){
              alert("添加失败");
          }
      })
    }
}

function delectRemark(obj) {
    var remarkId=obj;
    $.post("${pageContext.request.contextPath}/remark/delectRemark.action",
        {"remarkId":remarkId},
        function (date) {
        console.log(date);
        console.log(typeof date);
            if(date==true){
                window.alert("删除评语成功")
                window.location.href="${pageContext.request.contextPath}/remark/remarkList.action";
            }else{
                window.alert("删除失败")
                window.location.href="${pageContext.request.contextPath}/remark/remarkList.action"
            }
        }
    )

}
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>